package com.example.taluo.mapper;

import com.example.taluo.entity.Room;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/*** @Author supersaiya

* @Description TODO

* @Date 2025/2/15 18:22

* @Version 1.0*/
@Mapper
public interface RoomMapper {

    // 插入房间信息
    @Insert("INSERT INTO Room (roomId, creatorId, password, maxPlayers, status, addTime, updateTime, closedAt) " +
            "VALUES (#{roomId}, #{creatorId}, #{password}, #{maxPlayers}, #{status}, #{addTime}, #{updateTime}, #{closedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertRoom(Room room);

    // 根据房间逻辑 ID 查询房间
    @Select("SELECT * FROM Room WHERE roomId = #{roomId}")
    Room selectRoomByRoomId(String roomId);

    // 更新房间状态
    @Update("UPDATE Room SET status = #{status}, updateTime = #{updateTime} WHERE roomId = #{roomId}")
    void updateRoomStatus(@Param("roomId") String roomId, @Param("status") Byte status, @Param("updateTime") LocalDateTime updateTime);

    // 删除房间
    @Delete("DELETE FROM Room WHERE roomId = #{roomId}")
    void deleteRoomByRoomId(String roomId);

    // 查询所有房间（可选）
    @Select("SELECT * FROM Room")
    List<Room> selectAllRooms();
}